package org.odefu.model.project;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class Project implements Named
{
	private final List<TableTemplate> templates = new ArrayList<TableTemplate>();

	private final List<Table> tables = new ArrayList<Table>();

	private final String name;

	public Project(final String name)
	{
		this.name = name;
	}

	@Override
	public String name()
	{
		return name;
	}

	public List<TableTemplate> templates()
	{
		return Collections.unmodifiableList(templates);
	}

	public List<Table> tables()
	{
		return Collections.unmodifiableList(tables);
	}

	public TableTemplate template(final int index)
	{
		return templates.get(index);
	}

	public Table table(final int index)
	{
		return tables.get(index);
	}

	public void addTemplate(final TableTemplate template)
	{
		if (!templates.contains(template))
		{
			templates.add(template);
		}
	}

	public void addTemplate(final TableTemplate template, final int index)
	{
		if (!templates.contains(template))
		{
			templates.add(index, template);
		}
	}

	public void addTable(final Table table)
	{
		if (!tables.contains(table))
		{
			tables.add(table);
		}
	}

	public void addTable(final Table table, final int index)
	{
		if (!tables.contains(table))
		{
			tables.add(index, table);
		}
	}

	public TableTemplate removeTemplate(final int index)
	{
		return templates.remove(index);
	}

	public boolean removeTemplate(final TableTemplate template)
	{
		return templates.remove(template);
	}

	public Table removeTable(final int index)
	{
		return tables.remove(index);
	}

	public boolean removeTable(final Table table)
	{
		return tables.remove(table);
	}
}
